package com.feifan.monthhelper.bean.db;

import android.arch.persistence.room.ColumnInfo;
import android.arch.persistence.room.Entity;
import android.arch.persistence.room.PrimaryKey;
import android.arch.persistence.room.TypeConverters;
import android.os.Parcel;
import android.os.Parcelable;

import com.feifan.monthhelper.db.conventer.DateConverter;
import com.feifan.monthhelper.db.conventer.StringListConventer;

import java.util.Date;
import java.util.List;

@Entity(tableName = "day_record")
@TypeConverters({StringListConventer.class, DateConverter.class})
public class DayRecordBean implements Parcelable, Comparable<DayRecordBean> {
    @PrimaryKey
    @ColumnInfo(name = "create_date")
    public Date createDate;
    //喝热水
    public boolean hot_water;
    //吃水果
    public boolean fruit;
    //运动
    public boolean sports;
    //吃早餐
    public boolean breakfast;
    //排便
    public boolean defecate;
    //月经量
    public int blood_level;
    //疼痛程度
    public int pain_level;
    //爱爱保护
    public List<String> protects;
    //月经状态 0：无/1：月经期/2：预测月经期/3：安全期/4：排卵期
    public int state;

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeLong(this.createDate != null ? this.createDate.getTime() : -1);
        dest.writeByte(this.hot_water ? (byte) 1 : (byte) 0);
        dest.writeByte(this.fruit ? (byte) 1 : (byte) 0);
        dest.writeByte(this.sports ? (byte) 1 : (byte) 0);
        dest.writeByte(this.breakfast ? (byte) 1 : (byte) 0);
        dest.writeByte(this.defecate ? (byte) 1 : (byte) 0);
        dest.writeInt(this.blood_level);
        dest.writeInt(this.pain_level);
        dest.writeStringList(this.protects);
        dest.writeInt(this.state);
    }

    public DayRecordBean() {
    }

    protected DayRecordBean(Parcel in) {
        long tmpCreateDate = in.readLong();
        this.createDate = tmpCreateDate == -1 ? null : new Date(tmpCreateDate);
        this.hot_water = in.readByte() != 0;
        this.fruit = in.readByte() != 0;
        this.sports = in.readByte() != 0;
        this.breakfast = in.readByte() != 0;
        this.defecate = in.readByte() != 0;
        this.blood_level = in.readInt();
        this.pain_level = in.readInt();
        this.protects = in.createStringArrayList();
        this.state = in.readInt();
    }

    public static final Parcelable.Creator<DayRecordBean> CREATOR = new Parcelable.Creator<DayRecordBean>() {
        @Override
        public DayRecordBean createFromParcel(Parcel source) {
            return new DayRecordBean(source);
        }

        @Override
        public DayRecordBean[] newArray(int size) {
            return new DayRecordBean[size];
        }
    };

    @Override
    public int compareTo(DayRecordBean o) {
        //升序
        return createDate.compareTo(o.createDate);
    }
}
